package com.woniu.mall.task;

import com.woniu.mall.constant.OrderConstants;
import com.woniu.mall.constant.ProductConstants;
import com.woniu.mall.pojo.MallProduct;
import com.woniu.mall.service.IMallProductService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;
@Component
@Slf4j
public class ProductSaleTask {
    @Autowired
    private IMallProductService productService;

    /**
     * 设置商品销量展示
     */
    @Scheduled(cron = "0 0 1 * * ?") // 每天凌晨1点执行一次
    public void getSortBySale() {
        List<MallProduct> allProducts = productService.list();
        for (MallProduct product : allProducts) {
            Integer sale = product.getSale();
            if (sale > 99) {
                product.setShowSale("100+");
            } else if (sale > 199) {
                product.setShowSale("200+");
            } else if (sale > 399) {
                product.setShowSale("400+");
            } else if (sale > 599) {
                product.setShowSale("600+");
            } else if (sale > 799) {
                product.setShowSale("800+");
            } else if (sale > 999) {
                product.setShowSale("1000+");
            } else {
                product.setShowSale(sale.toString());
            }
        }
    }
}
